/*
ID:luongho3
LANG:JAVA
TASK:pprime
 */
package usaco.training.chap1.sec5;

import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class pprime {
	
	static int  a, b;
	static int[] num = new int[100000];
	static int nn;

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("pprime.in"));
		PrintStream ps = new PrintStream(new File("pprime.out"));
		System.setOut(ps);
		num[0] = 2;
		num[1] = 3;
		num[2] = 5;
		num[3] = 7;
		nn = 4;
		int ndig = 1;
		for (int i=0;i<=9999;++i) {
			if (i > 9) {
				if (i < 100) {
					int n = i / 10;
					if (n % 2 == 0 || n % 5 == 0) {
						i += 9;
						continue;
					}
				}
				else if (i < 1000) {
					int n = i / 100;
					if (n % 2 == 0 || n % 5 == 0) {
						i += 99;
						continue;
					}
				}
				else if (i < 10000) {
					int n = i / 1000;
					if (n % 2 == 0 || n % 5 == 0) {
						i += 900;
						continue;
					}
				}
			}
			if (i > 0) {
				check(i);
			}
			for (int j=0;j<=9;++j) {
				if (i == 0) {
					continue;
				}
				check(i,j);
			}
		}
		Arrays.sort(num, 0, nn);
//		System.out.println(nn);
		int from, to;
		a = scanner.nextInt();
		b = scanner.nextInt();
		from = Arrays.binarySearch(num, 0, nn, a);
		if (from < 0) {
			from = -from - 1;
		}
		to = Arrays.binarySearch(num, 0, nn, b);
		if (to < 0) {
			to = -to - 2;
		}
		for (int i=from;i<=to;++i) {
			System.out.println(num[i]);
		}
	}

	private static void check(int i, int j) {
		int n = i;
		n *= 10;
		n += j;
		while (i > 0) {
			n *= 10;
			n += i % 10;
			i /= 10;
		};
		if (prime(n)) {
			num[nn] = n;
			nn++;
		}
	}

	private static void check(int i) {
		int n = i;
		while (i > 0) {
			n *= 10;
			n += i % 10;
			i /= 10;
		}
		if (prime(n)) {
			num[nn] = n;
			nn++;
		}
	}

	private static boolean prime(int n) {
		int i = 2;
		while (i * i <= n) {
			if (n % i == 0) {
				return false;
			}
			else {
				++i;
			}
		}
		return true;
	}

}
